#include "PerformanceTimer.h"
#include <windows.h>

PerformanceTimer::PerformanceTimer(void)
{
	memset(this, 0, sizeof(PerformanceTimer));
}

PerformanceTimer::~PerformanceTimer(void)
{

}

void PerformanceTimer::Initialize()
{
	QueryPerformanceFrequency((LARGE_INTEGER*)&m_cntsPerSec);
	m_secsPerCnt = 1.0f / (float)m_cntsPerSec;
}

float PerformanceTimer::Update(void)
{
	if(m_paused)
		return m_deltaTime = 0.0f;

	QueryPerformanceCounter((LARGE_INTEGER*)&m_currTimeStamp);
	m_deltaTime = (m_currTimeStamp - m_prevTimeStamp) * m_secsPerCnt;
	m_prevTimeStamp = m_currTimeStamp;

	return m_deltaTime;
}

float PerformanceTimer::DeltaTime(void)
{
	return m_deltaTime;
}

void PerformanceTimer::Pause(void)
{
	m_paused = true;
}

void PerformanceTimer::Resume(void)
{
	m_paused = false;
	Reset();
}

void PerformanceTimer::Reset(void)
{
	QueryPerformanceCounter((LARGE_INTEGER*)&m_prevTimeStamp);
}


/////////////////////
// Brief: FPS counter
void FPS::Update(float dt)
{
	if((elapsedTime += dt) >= 1.0f)
	{
		fps = frameCount;
		Reset();
	}

	frameCount++;
}
